# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.18.1)

# Declares and names the project.

project("cairoTestInAndroid")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
set(my_lib_path ${CMAKE_SOURCE_DIR}/../../../libs)
add_library(cairo SHARED IMPORTED)
set_target_properties(cairo PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libcairo.so)
add_library(freetype SHARED IMPORTED)
set_target_properties(freetype PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libfreetype.so)
add_library(glib SHARED IMPORTED)
set_target_properties(glib PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libglib-2.0.so)
add_library(libpng SHARED IMPORTED)
set_target_properties(libpng PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libpng16.so)
add_library(libfontconfig SHARED IMPORTED)
set_target_properties(libfontconfig PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libfontconfig.so)
add_library(libpixman SHARED IMPORTED)
set_target_properties(libpixman PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libpixman-1.so)
add_library(libpcre2 SHARED IMPORTED)
set_target_properties(libpcre2 PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libpcre2-8.so)
add_library(libintl SHARED IMPORTED)
set_target_properties(libintl PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libintl.so)
add_library(cpufeature SHARED IMPORTED)
set_target_properties(cpufeature PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libcpufeatures.so)
add_library(libxml2 SHARED IMPORTED)
set_target_properties(libxml2 PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libxml2.so)


#message("ANDROID_ABI " ${ANDROID_ABI})

add_library( # Sets the name of the library.
        cairoTestInAndroid

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        native-lib.cpp
        java_bitmap.cpp
        draw_star_test.cpp
        )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

find_library(c++_shared-lib c++_shared)

find_library(jnigraphics-lib jnigraphics)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_include_directories(cairoTestInAndroid PUBLIC
                                            include
                                            include/cairo
                                            include/pixman
        )

target_link_libraries( # Specifies the target library.
        cairoTestInAndroid

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib}
        ${c++_shared-lib}
        ${jnigraphics-lib}
        cairo
        freetype
        glib
        libpng
        libfontconfig
        libpixman
        libpcre2
        libintl
        cpufeature
        libxml2
        )